package org.example.test;

import org.apache.commons.io.FileUtils;

import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import java.util.function.Function;
import java.util.stream.Collectors;

public class SteamDemo {


    public static void main(String[] args) {

        test4();

        TestA testA = new TestA();
        testA.hello("hello", new Function<String, String>() {
            @Override
            public String apply(String s) {
                System.out.println("s="+s);
                return "hello"+s;
            }
        });

    }


    static void test1(){
        List<String> names = new ArrayList<>();
        Collections.addAll(names,"张三丰","张无忌","赵敏","张三","王二娃","张东方不败");
        names.stream().filter(s -> s.startsWith("张")).filter(s -> s.length()==5).forEach(s -> System.out.println(s));
//.stream()是将集合names转换为stream流
//filter()是过滤器，是针对stream中的所有元素的筛选条件
//s -> 使用了Lambda表达式，含义为：创建一个对象（对象类型为stream中元素相同类型），箭头后是筛选条件
//同样的在foreach中使用了Lambda表达式，箭头后是操作
    }

    static void test2(){
        List<String> words = Arrays.asList("Hello","World");
        List<String> letters = words.stream().flatMap(word->Arrays.stream(word.split(""))).collect(Collectors.toList());
    }

    static void test3(){
        List<List<Integer>> listOfLists = Arrays.asList(
                Arrays.asList(1, 2, 3),
                Arrays.asList(4, 5),
                Arrays.asList(6, 7, 8)
        );

        List<Integer> flattenedList = listOfLists.stream()
                .flatMap(list -> list.stream())  // Flattening step
                .toList();
        System.out.println("拍平:" + flattenedList);
    }

    static void test4()  {

        String taskPath = "D:\\poifile\\test";
        try {
            FileUtils.deleteDirectory(new File(taskPath));
        } catch (IOException e) {
            throw new RuntimeException(e);
        }

        System.out.println("删除成功");
    }




    static class TestA{

        String hello(String hello, Function<String,String> function){
            return function.apply(hello);
        }


    }


}
